package com.mcbbs.web.service.impl;

import com.mcbbs.web.entity.UsersSilverCoin;
import com.mcbbs.web.mapper.UsersSilverCoinMapper;
import com.mcbbs.web.service.UsersSilverCoinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("userSilverCoinService")
public class UsersSilverCoinServiceImpl implements UsersSilverCoinService {
    @Autowired
    private UsersSilverCoinMapper usersSilverCoinMapper;
    @Override
    public List<UsersSilverCoin> getAll() {

        return usersSilverCoinMapper.querys();
    }

    @Override
    public UsersSilverCoin getCoinByLastName(String lastName) {
        return usersSilverCoinMapper.queryByLastName(lastName);
    }

    @Override
    public int addCoin(String lastName, double balance) {
        if(lastName!=null&&balance>0){
            UsersSilverCoin usersSilverCoin = usersSilverCoinMapper.queryByLastName(lastName);
            if(usersSilverCoin!=null){
//                设置用户实体类的金额为原本金额加上参数的金额
                usersSilverCoin.setBalance(usersSilverCoin.getBalance()+balance);

            }
//            不存在该用户
            return -2;
        }
//        提交的参数有问题
        return -1;
    }

//    减少指定玩家的银币
    @Override
    public int reduceCoin(String lastName, double balance) {
        if (lastName!=null&&balance>0){

        }
        return 0;
    }

    @Override
    public int setCoin(String lastName, double balance) {
        return 0;
    }
}
